<template>
	<page-meta>
		<navigation-bar :title="nbTitle" :title-icon-radius="titleIconRadius" :subtitle-color="nbFrontColor"
			:loading="nbLoading" :front-color="nbFrontColor" :background-color="nbBackgroundColor" />
	</page-meta>
	<view class="content">
		<!-- 轮播图 -->
		<swiper class="swiper-box" :circular="true" :autoplay="true" :indicator-dots="true">
			<swiper-item v-for="(item, index) in sceneList" :key="index">
				<view class="swiper-item" @click="clickBannerItem(item)">
					<image :src="imageList(item.educationUrl)" mode="aspectFill" :draggable="false" />
				</view>
			</swiper-item>
		</swiper>
		<!-- 宫格组件 -->
		<view class="grid" v-show="permissions==0">
			<uni-grid :column="4" :highlight="true" :showBorder="false">
				<uni-grid-item>
					<view class="grid-item-box" style="background-color: #fff;" @click="gotoClassNews">
						<text class="iconfont" style="font-size: 45px;">&#x1006a;</text>

						<text class="text">班级通讯</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view @click="gotoClassScheduleCard" class="grid-item-box" style="background-color: #fff;">
						<text class="iconfont" style="font-size: 45px;">&#xe62a;</text>
						<text class="text">课程表</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" style="background-color: #fff;" @click="gotoHomeWork">
						<text class="iconfont" style="font-size: 45px;">&#xe746;</text>
						<text class="text">家庭作业</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" style="background-color: #fff;" @click="gotoCampusFees">
						<text class="iconfont" style="font-size: 45px;">&#xe608;</text>
						<text class="text">校园收费</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
		<!-- 宫格组件 -->
		<view class="grid">
			<uni-grid :column="4" :highlight="true" :showBorder="false">
				<uni-grid-item>
					<view class="grid-item-box" style="background-color: #fff;" @click="gotoNews">
						<text class="iconfont" style="font-size: 45px;">&#xe6e1;</text>
						<text class="text">校园快讯</text>
					</view>
				</uni-grid-item>

				<uni-grid-item>
					<view class="grid-item-box" style="background-color: #fff;" @click="gotoEducation">
						<text class="iconfont" style="font-size: 45px;">&#xe65f;</text>
						<text class="text">教育摘要</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view @click="gotoHSCircle" class="grid-item-box" style="background-color: #fff;">
						<text class="iconfont" style="font-size: 45px;">&#xe60b;</text>
						<text class="text">家校圈</text>
					</view>
				</uni-grid-item>
				<uni-grid-item>
					<view class="grid-item-box" style="background-color: #fff;" @click="gotoAdvice">
						<text class="iconfont" style="font-size: 45px;">&#xe631;</text>
						<text class="text">校长信箱</text>
					</view>
				</uni-grid-item>
			</uni-grid>
		</view>
		<!-- 通知 -->
		<view class="footer-top">
			<view class="top">
				<text class="iconfont" style="font-size: 30px;">&#xe616;</text>
				<text
					style="font-size: 28rpx; vertical-align: top; margin-left: 20rpx; margin-right: 450rpx;">学校通知</text>
				<text class="iconfont" style="font-size: 30rpx; vertical-align: top;"
					@click="gotoNews">更多&#xe64c;</text>

			</view>
			<view v-for="(slide, i) in noticeList" :index="i" :key="i">
				<view class="footer" @click="gotoDetails(slide)">
					<view class="footer-image">
						<image :src="imageList(slide.noticeUrl)"></image>
					</view>
					<view class="footer-content">
						<view class="content-title">
							{{slide.noticeTitle}}
						</view>
						<view>
							<mp-html class="content-body" :content="slide.noticeContent" />
						</view>
						<view class="date" :date="slide.createTime" format="MM/dd">
							{{slide.createTime}}
						</view>
					</view>
				</view>

			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCurrNoticeLimit,
		getCurrEducationLimit,
	} from "@/api/home/home.js"
	import {
		profileClass
	} from "@/api/system/user.js"
	export default {
		data() {
			return {
				nbTitle: '花季护航',
				titleIconRadius: '20px',
				nbLoading: false,
				nbFrontColor: '#000000',
				nbBackgroundColor: '#fcc10d',
				current: 0,
				swiperDotIndex: 0,
				noticeList: [],
				sceneList: [],
				permissions: this.$store.state.user.category
			}

		},
		onLoad() {},
		onShow() {
			// console.log(this.$store.state.user.classId);
			getCurrNoticeLimit().then(res => {

				if (res.code == 200) {
					this.noticeList = res.data;
				}
			})
			getCurrEducationLimit().then(res => {
				if (res.code == 200) {
					this.sceneList = res.data;
				}
			})
		},
		methods: {
			//关于我们
			onNavigationBarButtonTap(e) {
				if (e.float == "right") {
					uni.navigateTo({
						url: `/pages/home/about/index`
					})
				}
				if (e.float == "left") {
					uni.navigateTo({
						url: `/pages/home/search/index`
					})
				}
			},
			//轮播图详情
			clickBannerItem(event) {
				uni.navigateTo({
					url: '/pages/home/education-details/index?item=' + encodeURIComponent(JSON.stringify(
						event))
				})
			},
			//通知详情
			gotoDetails(event) {
				uni.navigateTo({
					url: '/pages/home/news-details/index?item=' + encodeURIComponent(JSON.stringify(event))
				})

			},
			//班级通讯
			gotoClassNews() {
				profileClass().then((res) => {
					// console.log(res);
					if (res.data.classId) {
						uni.navigateTo({
							url: '/pages/home/classNews/index?classId=' + res.data.classId
						})
					} else {
						uni.showToast({
							title: '请先加入班级',
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			//课程表
			gotoClassScheduleCard() {
				profileClass().then((res) => {
					if (res.data.classId) {
						uni.navigateTo({
							url: '/pages/home/classScheduleCard/index?classId=' + res.data
								.classId
						})
					} else {
						uni.showToast({
							title: '请先加入班级',
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			//家庭作业
			gotoHomeWork() {
				profileClass().then((res) => {
					if (res.data.classId) {
						uni.navigateTo({
							url: '/pages/home/homeWork/index?classId=' + res.data.classId
						})
					} else {
						uni.showToast({
							title: '请先加入班级',
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			//校园收费
			gotoCampusFees() {
				profileClass().then((res) => {
					if (res.data.classId) {
						uni.navigateTo({
							url: '/pages/home/campusFees/index?classId=' + res.data.classId
						})
					} else {
						uni.showToast({
							title: '请先加入班级',
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			//校园快讯
			gotoNews() {
				uni.navigateTo({
					url: '/pages/home/news/index'
				})
			},

			//教育摘要
			gotoEducation() {
				uni.navigateTo({
					url: '/pages/home/education/index'
				})
			},
			//家校圈
			gotoHSCircle() {
				uni.navigateTo({
					url: '/pages/home/homeSchoolCircle/index'
				})
			},
			// 校长信箱
			gotoAdvice() {
				uni.navigateTo({
					url: '/pages/home/advice/index'
				})
			},

		},
		computed: {
			imageList() {
				return function(e) {
					if (e != null) {
						return e.split(",")[0]
					}
				}
			}
		},
	}
</script>
<style lang="scss">
	.text {
		text-align: center;
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15rpx 0;
	}


	.swiper {
		height: 300rpx;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		color: #fff;
		height: 300rpx;
		line-height: 300rpx;
	}

	.footer {
		margin: 20rpx;
		display: flex;
		justify-content: space-between;

		.footer-image {
			display: block;
			width: 450rpx;
			height: 250rpx;
			margin-right: 10rpx;

			image {
				width: 350rpx;
				height: 250rpx;
			}
		}

		.footer-content {
			display: flex;
			flex-direction: column;
			width: 529rpx;
			margin-right: 380rpx;
		}
	}

	.content-title {
		color: black;
		font-weight: bold;
		width: 529rpx;
		font-size: 38rpx;
		max-width: 310rpx;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.content-body {
		font-size: 30rpx;
		overflow: hidden;
		-webkit-line-clamp: 2;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		margin-bottom: 25rpx;
	}

	.date {
		margin-top: 75rpx;
	}

	.footer-top {
		margin-top: 40rpx;
		background-color: #fff;
		display: flex;
		flex-direction: column;
	}

	.notice-content {
		display: block;
		font-family: PingFangSC-Regular;
		font-size: 14rpx;
		color: #482929;
		letter-spacing: 0;
		line-height: 20px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: normal;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
		/*规定最多显示两行*/
	}

	.top {
		font-size: 27rpx;
		font-weight: bold;
		line-height: 70rpx;
		height: 70rpx;
		border-bottom: 1rpx #dcdcdc solid;
	}
</style>
